In [4]:
using Plots,ApproxFun,Interact,Reactive
plotly();

KdV with Neumann $$u_t + 6uu_x + u_{xxx}=0$$

Evaluate the first cell to start the plot, then the second cell to evolve the plot. Evaluating the second cell will continue evolving the solution. It may take two times before it works.


In [5]:
u0=Fun(x->2exp(-x^2),[-10.,10.])
d=domain(u0);D=Derivative(d)
g(y)=-6.y*y'
x=Signal(u0);map(y->plot(y;ylims=(-1.,3.)),x)


[Plots.jl] Initializing backend: plotly
Out[5]:

In [6]:
u0=BDF2([neumann(d);rdirichlet(d)],-D^3,g,zeros(3),u0,0.004,300,x,10E-7);

KS with periodic boundary conditions $$u_t + uu_x + u_{xx} + u_{xxxx}=0$$


In [7]:
u0,t=Fun(x->cos(x/16)*(1+sin(x/16)),Fourier([0.,32π])),0.0
d=domain(u0);D=Derivative(d)
L = -D^2-D^4
N(u,t) = -u*u'
x=Signal(u0);map(y->plot(y;xlims=(0,32π),ylims=(-3.,3.)),x)


Out[7]:

In [8]:
u0,t=ETDRK4(L,N,u0,t,0.1,300,x,1e-8);

Burgers with periodic boundary conditions $$u_t + uu_x - \epsilon u_{xx}=0$$


In [9]:
ϵ=0.03;
u0,t=Fun(x->exp(-10sin(x/2)^2),Fourier()),0.0
d=domain(u0);D=Derivative(d)
L = ϵ*D^2
N(u,t) = -u*u'
x=Signal(u0);map(y->plot(y;xlims=(-π,π),ylims=(0.,1.)),x)


Out[9]:

In [10]:
u0,t=ETDRK4(L,N,u0,t,0.01,100,x,1e-8);

Dullin—Gottwald—Holm Equation with periodic boundary conditions \begin{align*}

m_t + c_0u_x + um_x + 2mux & = -\gamma u{xxx},\ u - \alpha^2 u_{xx} & = m. \end{align*}


In [11]:
c0,γ,α,d = 0.1,0.5,0.2,PeriodicInterval()
u0,t=Fun(x->(sin(2x)+0.5sin(4x))/(1+sin(x/2)^2),Laurent(d)),0.0
sp=space(u0);D=Derivative(sp)
Lum = cache(I-α^2*D^2)
Lmu = cache(inv(Lum))
L = cache(-Lmu*(c0*D+γ*D^3))
N(u,t) = -Lmu*(u*(Lum*u)'+2*u'*(Lum*u))
x=Signal(u0);map(y->plot(real(y);xlims=(-π,π),ylims=(-1.5,1.5)),x)


Out[11]:

In [12]:
u0,t=ETDRK4(L,N,u0,t,0.005,200,x,1e-8);